//
//  LocaData.m
//  图片故事
//
//  Created by 大帅逼 on 16/1/6.
//  Copyright © 2016年 helloApp. All rights reserved.
//

#import "LocaData.h"
#import "OptionModal.h"
#import "PrecessOptionModel.h"
#import "PhotoQualitModel.h"

@implementation LocaData

+ (void)saveUserInfo:(UserInfoModal *)userInfo {

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    [userDefaults setObject:userInfo.userHead forKey:@"userHead"];
    [userDefaults setObject:userInfo.userId forKey:@"userId"];
    [userDefaults setObject:userInfo.userName forKey:@"userName"];
    [userDefaults setObject:userInfo.userPwd forKey:@"userPwd"];
    
    [userDefaults synchronize];
}

+ (UserInfoModal *)readUserInfo {

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    UserInfoModal *userInfo = [[UserInfoModal alloc] init];
    
    userInfo.userHead = [userDefaults objectForKey:@"userHead"];
    userInfo.userId = [userDefaults objectForKey:@"userId"];
    userInfo.userName = [userDefaults objectForKey:@"userName"];
    userInfo.userPwd = [userDefaults objectForKey:@"userPwd"];
    
    return userInfo;
}

+ (BOOL)isLogin {

    if ([self readUserInfo].userName.length > 0) {
        
        return YES;
    }else {
    
        return NO;
    }
}

+ (NSArray *)readSetOption {

    NSArray *optionNameArray = [[NSArray alloc] initWithObjects:@"图片质量",@"意见反馈",@"告诉朋友",@"关于我们", @"退出登录",nil];
    
    NSArray *optionIconArray = [[NSArray alloc] initWithObjects:@"img_quality",@"write_icon",@"tell_icon",@"about_icon", @"logOut",nil];
    
    NSMutableArray *optionArray = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < optionNameArray.count; i ++) {
        
        OptionModal *option = [[OptionModal alloc] init];
        
        option.optionImage = [optionIconArray objectAtIndex:i];
        
        option.optionTitle = [optionNameArray objectAtIndex:i];
        
        [optionArray addObject:option];
    }
    
    return [optionArray copy];
}

+ (NSArray *)readPrecessOption {

    NSArray *precessOptionNameArray = [[NSArray alloc] initWithObjects:@"滤镜",@"特效",@"调节",@"水印", nil];
    
    NSArray *precessOptionImageArray = [[NSArray alloc] initWithObjects:@"filter_icon",@"effect_icon",@"witle",@"stringMark_icon", nil];
    
    NSMutableArray *precessOptionArray = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < precessOptionNameArray.count; i++) {
        
        PrecessOptionModel *optionModel = [[PrecessOptionModel alloc] init];
        
        [optionModel setOptionImageName:[precessOptionImageArray objectAtIndex:i]];
        
        [optionModel setOptionTilte:[precessOptionNameArray objectAtIndex:i]];
        
        [precessOptionArray addObject:optionModel];
    }
    
    return [precessOptionArray copy];
}

+ (NSArray *)readSetPhotoQualit {
    
    NSArray *photoQualitNameArray = [[NSArray alloc] initWithObjects:@"高清",@"普通",@"一般", nil];
    
    
    NSMutableArray *photoQualitArray = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < photoQualitNameArray.count; i ++) {
        
        PhotoQualitModel *photoQualit = [[PhotoQualitModel alloc] init];
        
        photoQualit.photoTitle = [photoQualitNameArray objectAtIndex:i];
        photoQualit.photoImage = @"circle_icon";
        
        [photoQualitArray addObject:photoQualit];
        
        
    }
    return [photoQualitArray copy];
}

+ (void)setPhotoQualitWithIndex:(NSInteger)index {

    if (index == 2) {
        
        [[NSUserDefaults standardUserDefaults] setObject:@1024 forKey:@"photoQualit"];
    }else if (index == 1) {
    
        [[NSUserDefaults standardUserDefaults] setObject:@2048 forKey:@"photoQualit"];
    }else {
    
        [[NSUserDefaults standardUserDefaults] setObject:@4096 forKey:@"photoQualit"];
    }
    
    // 更新当前显示的图片
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changePhotoQualit" object:nil];
}

+ (NSInteger)readPhotoQualit {
    
    NSInteger index;

    NSNumber *kNumber = [[NSUserDefaults standardUserDefaults] objectForKey:@"photoQualit"];
    
    switch ([kNumber integerValue]) {
        case 1024:
            
            index = 2;
            break;
        case 2048:
            
            index = 1;
            break;
        case 4096:
            
            index = 0;
            break;
            
        default:
            
            index = 2;
            break;
    }
    
    return index;
}

+ (NSArray *)readMarkArray {
    
    NSArray *markTitleArray = [[NSArray alloc] initWithObjects:@"mark_01",@"mark_02",@"mark_03",@"mark_04",@"mark_05",@"mark_06",@"mark_07",@"mark_08",@"mark_09",@"mark_10",@"mark_11",@"mark_12", nil];

    return markTitleArray;
}

@end
